# coding=utf-8
import arcpy
import xlrd
import xlwt
import os

inpath = ur"D:\sde_copy\地理国情监测数据测试"
outpath = r"D:\sde_copy\DLGQ.gdb"

workspace = inpath
ds_name = "LcrDataset"
fc_name = "V_LCRA"


class Record:
    def __init__(self):
        self.name = ""
        self.path = ""
        self.type = ""
        self.size = 0


# 循环向下遍历文件，收集特定文件类型的文件（以xxx结尾）
def list_fold_with_tag(root_path, all_files, ext):
    if os.path.isdir(root_path):
        files = os.listdir(root_path)
        for temp_file in files:
            current = os.path.join(root_path, temp_file)
            if os.path.isdir(current) and str(temp_file).lower().endswith(ext):
                all_files.append(current)
            else:
                list_fold_with_tag(current, all_files, ext)
    return all_files


def find_gdbs():
    gdb_fold = []
    list_fold_with_tag(inpath, gdb_fold, ".gdb")
    return gdb_fold


def find_fc_from_ds():
    fc_fold_with_dir = []
    for current_gdb_with_path in find_gdbs():
        arcpy.env.workspace = current_gdb_with_path
        for currentDS in arcpy.ListDatasets():
            if currentDS == ds_name:
                fcs = arcpy.ListFeatureClasses(feature_dataset=currentDS)
                print fcs
                for currentFC in fcs:
                    if currentFC == fc_name:
                        fc_fold_with_dir.append(os.path.join(arcpy.env.workspace, ds_name, currentFC))

    return fc_fold_with_dir

# def find_fcs():
#     fc_fold_with_path = []
#     for current_gdb in find_gdbs():
#         arcpy.env.workspace = current_gdb
#         dss = arcpy.ListDatasets()
#         fcs = arcpy.ListFeatureClasses()
#         for current_fc in fcs:
#             if current_fc == fc_name:
#                 fc_fold_with_path.append(os.path.join(arcpy.env.workspace, ds_name, current_fc))
#
#     return fc_fold_with_path


if __name__ == '__main__':
    find_fc_from_ds()

# print("============Start Merging==============")
# arcpy.Merge_management(samename_fcs, outpath + "/%s" % fc_name)
# print ("finish")
